home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 2 / Gekikoh Dennoh Club Vol. 2 (Japan).7z / Gekikoh Dennoh Club Vol. 2 (Japan) (Track 01).bin / tools / cd2pcmt / source.lzh / music_lib.c < prev    next >
Text File  |  1997-10-01  |  8KB  |  361 lines

  1. #include "cd2pcm.h"
  2. #include "extern.h"
  3.  
  4.  
  5. /* bin を時間 bcd に変換する。*/
  6. int bin2time( int bin )
  7. {
  8.     int i;
  9.     int ans = 0;
  10.  
  11. static  int bin2time_tbl[2] = { 60*75, 75 };
  12.  
  13.     for( i = 0 ; i < 2 ; i++ )
  14.     {
  15.         ans  = ans << 8;
  16.         ans += bin / bin2time_tbl[i];
  17.         bin  = bin % bin2time_tbl[i];
  18.     }
  19.     ans  = ans << 8;
  20.     ans += bin;
  21.  
  22.     return( ans );
  23. }
  24.  
  25. /* 時間 bcd を bin に変換する。*/
  26. int time2bin( int time )
  27. {
  28. /*    00:mm:ss:xx 何分何秒何1/75秒    */
  29.     return( ( (time >> 16) & 0xff ) * 60*75 +
  30.         ( (time >>  8) & 0xff ) * 75  +
  31.         (  time        & 0xff )  );
  32. }
  33.  
  34. /* 時間を秒に変換する */
  35. int adr2time( int address )
  36. {
  37.     int    ans;
  38.  
  39.     ans  = ( ( address >> 16 ) & 0xff ) * 60 * 75;    /* 分をフレームに変える */
  40.     ans += ( ( address >>  8 ) & 0xff ) * 75;    /* 秒をフレームに買える */
  41.     ans -= 2*75;                    /* 2秒補正する。 */
  42.     ans += (   address         & 0xff );        /* フレームをそのまま加える */
  43.  
  44.     return( ans );
  45. }
  46.  
  47. /* 演奏時間を表示する。*/
  48. void cd_play_list( void )
  49. {
  50. int leadout_address,min,max,i,start,end,cnt;
  51. char *s;
  52. if ( RedTOC( &leadout_address, &min, &max ) != 0 ){
  53.     printf(    "Leadout Track Address or ReadTOC Command error "
  54.         "のため演奏時間はわかりませんでした。\n");
  55.     return;
  56. }
  57. for( i = min ; i <= max ; i++ ){
  58.     if ( Music_inf( i, &start ) != 0 ){
  59.         printf(    "Start Track Address or ReadTOC Command error "
  60.             "のため演奏時間はわかりませんでした。\n");
  61.         return;
  62.     }
  63.     if ( i == min ){
  64.         if ( CDC_ID==SCSI_ID )
  65.             s=(void*)CDCTNAME(-1);
  66.         else    s=0;
  67.         if ( s!=0 ) printf("\n[%s]",NameCenter(s) );
  68.  
  69.         end = bin2time( time2bin(leadout_address) - 
  70.                 time2bin(start) );
  71.  
  72.         printf("\n全ての曲の演奏時間は%2d分%02d秒%02dです。\n",
  73.             (end >> 16) & 0xff, (end >> 8) & 0xff,
  74.              end & 0xff );
  75.         printf("  曲番号    演奏時間    開始時間");
  76.         printf("      終了時間\n");
  77.     }
  78.  
  79.     if ( i == max ){
  80.         end = bin2time( time2bin(leadout_address) -1);
  81.     } else {
  82.         if ( Music_inf( i+1, &end) != 0 ){
  83.             printf(    "Start Track Address or "
  84.                 "ReadTOC Command error "
  85.                 "のため演奏時間はわかりませんでした。\n");
  86.             return;
  87.         } else
  88.             end = bin2time( time2bin( end ) -1);
  89.     }
  90.     cnt = bin2time( time2bin(end) - time2bin(start) +1 );
  91.  
  92.     printf("%3d 曲目  %2d分%02d秒%02d  ",i,
  93.         (cnt >> 16) & 0xff, (cnt >> 8) & 0xff,
  94.          cnt & 0xff );
  95.  
  96.     printf("%2d分%02d秒%02d ~ %2d分%02d秒%02d",
  97.         (start >> 16) & 0xff, (start >> 8 ) & 0xff,
  98.         start & 0xff,
  99.         ( end  >> 16) & 0xff, ( end  >> 8 ) & 0xff,
  100.         end & 0xff );
  101.  
  102.     if ( CDC_ID==SCSI_ID )
  103.         s=(void*)CDCTNAME(i);
  104.     else    s=0;
  105.     if ( s!=0 ) printf("    %s",NameCenter(s) );
  106.  
  107.     printf("\n");
  108. }
  109. return;
  110. }
  111.  
  112. /* 現在の状態と演奏曲数を表示する。*/
  113. void cd_play_inf( void )
  114. {
  115.     int dumy,min,max;
  116.     PLYINF plyinf;
  117.     char *s;
  118.  
  119.     if ( RedTOC( &dumy, &min, &max ) == 0 )
  120.     {
  121.         if ( CDC_ID==SCSI_ID )
  122.             s=(void*)CDCTNAME(-1);
  123.         else    s=0;
  124.         if ( s!=0 ) printf("[%s]\n",NameCenter(s) );
  125.  
  126.         printf("曲番号は、%d ~ %d まで有効です。\n", min, max );
  127.  
  128.         if ( ChkPly( &plyinf ) == 0 )
  129.         {
  130.             if ( ( plyinf.fg & 0x1f ) == 0x12 )
  131.             {
  132.                 /* 中断している。 */
  133.                 printf("%d 曲目の %2d分%02d秒%02dで中断しています。",
  134.                     plyinf.track_no, 
  135.                     ( plyinf.time / 0x10000 ) & 0xff ,
  136.                     ( plyinf.time / 0x100   ) & 0xff ,
  137.                       plyinf.time & 0xff );
  138.  
  139.                 printf("現在の演奏時間は、%2d分%02d秒%02dです。\n",
  140.                     ( plyinf.address / 0x10000 ) & 0xff ,
  141.                     ( plyinf.address / 0x100   ) & 0xff ,
  142.                       plyinf.address & 0xff  );
  143.             }
  144.             else if ( ( plyinf.fg & 0x1f ) == 0x11 )
  145.             {
  146.                 /* 演奏している */
  147.                 printf("%d 曲目の %2d分%02d秒%02dを演奏中です。",
  148.                     plyinf.track_no,
  149.                     ( plyinf.time / 0x10000 ) & 0xff ,
  150.                     ( plyinf.time / 0x100   ) & 0xff ,
  151.                       plyinf.time & 0xff );
  152.  
  153.                 printf("現在の演奏時間は、%2d分%02d秒%02dです。\n",
  154.                     ( plyinf.address / 0x10000 ) & 0xff ,
  155.                     ( plyinf.address / 0x100   ) & 0xff ,
  156.                       plyinf.address & 0xff  );
  157.             }
  158.             else
  159.             {
  160.                 /* 演奏していない。*/
  161.             }
  162.         }
  163.         else
  164.             printf("Read Drive Status Command error \n");
  165.     }
  166.     else
  167.     {
  168.         printf(    "Leadout Track Address or ReadTOC Command error "
  169.             "のため演奏で来ませんでした。\n");
  170.     }
  171. }
  172.  
  173. /* 演奏を中断する。*/
  174. void cd_play_pause( void )
  175. {
  176.     if ( StpDsk() == 0 ){
  177.         printf("演奏を中断します。\n");
  178.     } else
  179.         printf("Pause/Resume Command error \n");
  180. }
  181.  
  182. /* 演奏時間を指定して演奏する。*/
  183. void cd_play2( int num, int start, int end )
  184. {
  185.     int leadout_address,adr;
  186.     int min,max;
  187.  
  188.     if ( RedTOC( &leadout_address, &min, &max ) == 0 )
  189.     {
  190.         if ( num != 0 )
  191.         {
  192.             /* 演奏時間は、オフセット指定 */
  193.             if ( num > max  )
  194.             {
  195.                 printf("曲番号の指定が大きすぎます。\n");
  196.                 return;
  197.             }
  198.             if ( Music_inf( num, &adr ) == 0 )
  199.             {
  200.                 start = start + time2bin(adr);
  201.                 if ( end != -1 )
  202.                     end = end + time2bin(adr);
  203.             }
  204.             else
  205.             {
  206.                 printf(    "Start Track Address or ReadTOC Command error "
  207.                     "のため演奏時間はわかりませんでした。\n");
  208.                 return;
  209.             }
  210.         }
  211.  
  212.         if ( end == -1 )
  213.             /* 最後まで演奏する */
  214.             end = time2bin(leadout_address) - 1;
  215.  
  216.         if ( time2bin(leadout_address)  -1 < start )
  217.         {
  218.             printf("演奏開始時間の設定が大きすぎます。\n");
  219.             return;
  220.         }
  221.         if ( time2bin(leadout_address) -1 < end )
  222.         {
  223.             printf("演奏終了時間の設定が大きすぎます。\n");
  224.             return;
  225.         }
  226.         
  227.  
  228.         /* 演奏開始 */
  229.         if ( PlyDsk( bin2time(start), bin2time(end) ) != 0 )
  230.             printf("Play Audio Begin ・ Play Audio Block Count Command error のため演奏できませんでした。\n");
  231.     }
  232.     else
  233.     {
  234.         printf(    "Leadout Track Address or ReadTOC Command error "
  235.             "のため演奏できませんでした。\n");
  236.     }
  237. }
  238.  
  239. /* 一曲だけ演奏する。*/
  240. void cd_play( int start, int end )
  241. {
  242.     int start_address,end_address,leadout_address;
  243.     int min,max;
  244.  
  245.     if ( RedTOC( &leadout_address, &min, &max ) == 0 )
  246.     {
  247.         if ( end == -1 )
  248.         {
  249.             /* 最後まで演奏する */
  250.             end = max;
  251.         }
  252.  
  253.         if ( ( start >= min && start <= max ) && ( end >= min && end <= max ) )
  254.         {
  255.             if ( Music_inf( start, &start_address ) == 0 )
  256.             {
  257.                 if ( end == max )
  258.                     end_address = leadout_address;
  259.                 else
  260.                 {
  261.                     if (Music_inf( end+1,&end_address ) != 0 )
  262.                     {
  263.                         printf(    "Start Track Address or "
  264.                             "ReadTOC Command error "
  265.                             "のため演奏できませんでした。\n");
  266.                         return;
  267.                     }
  268.                 }
  269.  
  270.                 /* 演奏開始 */
  271.                 end_address = bin2time( time2bin(end_address ) -1 );
  272.                 if ( PlyDsk( start_address, end_address ) == 0 )
  273.                     ;
  274.                 else
  275.                 {
  276.                     printf(    "Play Audio Begin ・ Play Audio Block "
  277.                         "Count Command error のため演奏できませんでした。"
  278.                         "\n");
  279.                 }
  280.             }
  281.             else
  282.             {
  283.                 printf(    "Start Track Address or ReadTOC "
  284.                     "Command error のため演奏できませんでした。\n");
  285.             }
  286.         }
  287.         else
  288.         {
  289.             printf(    "指定された曲番号は、存在しません。\n"
  290.                 "曲番号は、%d ~ %d まで有効です。\n", min, max );
  291.         }
  292.     }
  293.     else
  294.     {
  295.         printf( "Leadout Track Address or ReadTOC Command error "
  296.             "のため演奏できませんでした。\n");
  297.     }
  298. }
  299.  
  300. /* 全曲を演奏する。*/
  301. void cd_play_all( void )
  302. {
  303.     int start_address,leadout_address,min,max;
  304.  
  305.     if ( RedTOC( &leadout_address, &min, &max ) == 0 )
  306.     {
  307.         if ( Music_inf( min , &start_address ) == 0 )
  308.         {
  309.             leadout_address = bin2time( time2bin(leadout_address ) -1 );
  310.             if ( PlyDsk(start_address,leadout_address) == 0 ) /* 演奏開始 */
  311.                 ;
  312.             else
  313.             {
  314.                 printf(    "Play Audio Begin or Play Audio Block Count"
  315.                     " Command error のため演奏できませんでした。\n");
  316.             }
  317.         }
  318.         else
  319.         {
  320.             printf(    "Start Track Address or ReadTOC "
  321.                 "Command error のため演奏できませんでした。\n");
  322.         }
  323.     }
  324.     else
  325.     {
  326.         printf(    "Leadout Track Address or ReadTOC Command error "
  327.             "のため演奏できませんでした。\n");
  328.     }
  329. }
  330.  
  331.  
  332. /* 演奏を再開させる。*/
  333. void cd_play_resume( void )
  334. {
  335.     PLYINF plyinf;
  336.  
  337.     if ( ChkPly( &plyinf ) == 0 )
  338.     {
  339.         if ( ( plyinf.fg & 0x1f ) == 0x12 )
  340.         {
  341.             if ( Resume() == 0 )
  342.                 printf("演奏を再開します。\n");
  343.             else
  344.                 printf("演奏再開に失敗しました。\n");
  345.         }
  346.         else if ( ( plyinf.fg & 0x1f ) == 0x11 )
  347.         {
  348.             printf("現在演奏は、中断していません。\n");
  349.             cd2pcm_help();
  350.         }
  351.         else
  352.         {
  353.             printf("現在演奏していません。\n");
  354.         }
  355.     }
  356.     else
  357.     {
  358.         printf("Read Drive Status Command error \n");
  359.     }
  360. }
  361.